

#include <gtk/gtk.h>
#include "support.h"
#include "regflag.h"
#include "window.h"
#include "config.h"
#include "statusbar.h"
#include "memfill.h"
#include "run.h"
#include "widget.h"

/*################ static functions ##################*/
static void on_sid_changed(GtkEditable *entry, gpointer data);

/*############## Various registers and flags #####################*/
GtkWidget *sign_flag, *parity_flag, *carry_flag, *zero_flag, *aux_flag;
GtkWidget *program_counter, *stack_pointer;
GtkWidget *a_register, *b_register, *c_register, *d_register, *e_register, *h_register, *l_register,
		  *flags_register;
GtkWidget *mse_flag, *ei_flag;
GtkWidget *rst_55, *rst_65, *rst_75;
GtkWidget *mask_55,*mask_65,*mask_75;
GtkWidget *sid,*sod,*sde;

gint sign_value,parity_value,carry_value,zero_value,aux_value;
gint pc_value,sp_value;
gint a_value,b_value,c_value,d_value,e_value,h_value,l_value,f_value;
gint mse_value,ei_value;
gint rst55_value,rst65_value,rst75_value;
gint mask55_value,mask65_value,mask75_value;

gint psw_value,bc_value,de_value,hl_value;
gint sid_value,sod_value,sde_value;

/*######### Set all register values from there corssponding entries ########*/
void gsim_set_registers(void)
{
	sign_value=make_int__(gtk_entry_get_text(GTK_ENTRY(sign_flag)));
	parity_value=make_int__(gtk_entry_get_text(GTK_ENTRY(parity_flag)));
	carry_value=make_int__(gtk_entry_get_text(GTK_ENTRY(carry_flag)));
	zero_value=make_int__(gtk_entry_get_text(GTK_ENTRY(zero_flag)));
	aux_value=make_int__(gtk_entry_get_text(GTK_ENTRY(aux_flag)));
	pc_value=make_int__(gtk_entry_get_text(GTK_ENTRY(program_counter)));
	sp_value=make_int__(gtk_entry_get_text(GTK_ENTRY(stack_pointer)));
	a_value=make_int__(gtk_entry_get_text(GTK_ENTRY(a_register)));
	b_value=make_int__(gtk_entry_get_text(GTK_ENTRY(b_register)));
	c_value=make_int__(gtk_entry_get_text(GTK_ENTRY(c_register)));
	d_value=make_int__(gtk_entry_get_text(GTK_ENTRY(d_register)));
	e_value=make_int__(gtk_entry_get_text(GTK_ENTRY(e_register)));
	h_value=make_int__(gtk_entry_get_text(GTK_ENTRY(h_register)));
	l_value=make_int__(gtk_entry_get_text(GTK_ENTRY(l_register)));
	f_value=make_int__(gtk_entry_get_text(GTK_ENTRY(flags_register)));
	mse_value=make_int__(gtk_entry_get_text(GTK_ENTRY(mse_flag)));
	ei_value=make_int__(gtk_entry_get_text(GTK_ENTRY(ei_flag)));
	rst55_value=make_int__(gtk_entry_get_text(GTK_ENTRY(rst_55)));
	rst65_value=make_int__(gtk_entry_get_text(GTK_ENTRY(rst_65)));
	rst75_value=make_int__(gtk_entry_get_text(GTK_ENTRY(rst_75)));
	mask55_value=make_int__(gtk_entry_get_text(GTK_ENTRY(mask_55)));
	mask65_value=make_int__(gtk_entry_get_text(GTK_ENTRY(mask_65)));
	mask75_value=make_int__(gtk_entry_get_text(GTK_ENTRY(mask_75)));
	sid_value=make_int__(gtk_entry_get_text(GTK_ENTRY(sid)));
	sod_value=make_int__(gtk_entry_get_text(GTK_ENTRY(sod)));
	sde_value=make_int__(gtk_entry_get_text(GTK_ENTRY(sde)));
	
	/*set all pairs*/
	set_psw();
	set_hl();
	set_de();
	set_bc(); 
}
/*########### Format all the values to their correct size ############*/
void gsim_format_registers(void)
{
	sign_value=sign_value&0x1;
	parity_value=parity_value&0x1;
	carry_value=carry_value&0x1;
	zero_value=zero_value&0x1;
	aux_value=aux_value&0x1;
	a_value=a_value&0xff;
	b_value=b_value&0xff;
	c_value=c_value&0xff;
	d_value=d_value&0xff;
	e_value=e_value&0xff;
	h_value=h_value&0xff;
	l_value=l_value&0xff;
	f_value=f_value&0xff;
	mse_value=mse_value&0x1;
	ei_value=ei_value&0x1;
	rst55_value=rst55_value&0x1;
	rst65_value=rst65_value&0x1;
	rst75_value=rst75_value&0x1;
	mask55_value=mask55_value&0x1;
	mask65_value=mask65_value&0x1;
	mask75_value=mask75_value&0x1;
	sid_value=sid_value&0x1;
	sod_value=sod_value&0x1;
	sde_value=sde_value&0x1;
}

/*###################### Set entries from registers ################*/
void gsim_set_entries(void)
{
	/*make the changed flag register value first*/
	gsim_format_registers();
	set_flags();
	
	gtk_entry_set_text(GTK_ENTRY(sign_flag),make_str__(sign_value,1));
	gtk_entry_set_text(GTK_ENTRY(parity_flag),make_str__(parity_value,1));
	gtk_entry_set_text(GTK_ENTRY(carry_flag),make_str__(carry_value,1));
	gtk_entry_set_text(GTK_ENTRY(zero_flag),make_str__(zero_value,1));
	gtk_entry_set_text(GTK_ENTRY(aux_flag),make_str__(aux_value,1));
	
	gtk_entry_set_text(GTK_ENTRY(program_counter),make_str__(pc_value,4));
	gtk_entry_set_text(GTK_ENTRY(stack_pointer),make_str__(sp_value,4));
	
	gtk_entry_set_text(GTK_ENTRY(a_register),make_str__(a_value,2));
	gtk_entry_set_text(GTK_ENTRY(b_register),make_str__(b_value,2));
	gtk_entry_set_text(GTK_ENTRY(c_register),make_str__(c_value,2));
	gtk_entry_set_text(GTK_ENTRY(d_register),make_str__(d_value,2));
	gtk_entry_set_text(GTK_ENTRY(e_register),make_str__(e_value,2));
	gtk_entry_set_text(GTK_ENTRY(h_register),make_str__(h_value,2));
	gtk_entry_set_text(GTK_ENTRY(l_register),make_str__(l_value,2));
	gtk_entry_set_text(GTK_ENTRY(flags_register),make_str__(f_value,2));
	
	gtk_entry_set_text(GTK_ENTRY(mse_flag),make_str__(mse_value,1));
	gtk_entry_set_text(GTK_ENTRY(ei_flag),make_str__(ei_value,1));
	gtk_entry_set_text(GTK_ENTRY(rst_55),make_str__(rst55_value,1));
	gtk_entry_set_text(GTK_ENTRY(rst_65),make_str__(rst65_value,1));
	gtk_entry_set_text(GTK_ENTRY(rst_75),make_str__(rst65_value,1));
	gtk_entry_set_text(GTK_ENTRY(mask_55),make_str__(mask55_value,1));
	gtk_entry_set_text(GTK_ENTRY(mask_65),make_str__(mask65_value,1));
	gtk_entry_set_text(GTK_ENTRY(mask_75),make_str__(mask75_value,1));
	gtk_entry_set_text(GTK_ENTRY(sid),make_str__(sid_value,1));
	gtk_entry_set_text(GTK_ENTRY(sod),make_str__(sod_value,1));
	gtk_entry_set_text(GTK_ENTRY(sde),make_str__(sde_value,1));
}

/*###################### reset all entries #######################*/
void reset_regflag(void)
{
	gtk_entry_set_text(GTK_ENTRY(sign_flag),"0");
	gtk_entry_set_text(GTK_ENTRY(parity_flag),"0");
	gtk_entry_set_text(GTK_ENTRY(carry_flag),"0");
	gtk_entry_set_text(GTK_ENTRY(zero_flag),"0");
	gtk_entry_set_text(GTK_ENTRY(aux_flag),"0");
	
	/*pc to start of memory,sp to end of memory*/
	GString *str;
	str=g_string_new("");
	g_string_append_printf(str,"%04X",gsim_values.memstart);
	gtk_entry_set_text(GTK_ENTRY(program_counter),str->str);
	str=g_string_truncate(str,0);
	g_string_append_printf(str,"%04X",gsim_values.memend);
	gtk_entry_set_text(GTK_ENTRY(stack_pointer),str->str);
	g_string_free(str,TRUE);
	
	gtk_entry_set_text(GTK_ENTRY(a_register),"00");
	gtk_entry_set_text(GTK_ENTRY(b_register),"00");
	gtk_entry_set_text(GTK_ENTRY(c_register),"00");
	gtk_entry_set_text(GTK_ENTRY(d_register),"00");
	gtk_entry_set_text(GTK_ENTRY(e_register),"00");
	gtk_entry_set_text(GTK_ENTRY(h_register),"00");
	gtk_entry_set_text(GTK_ENTRY(l_register),"00");
	gtk_entry_set_text(GTK_ENTRY(flags_register),"00");
	
	gtk_entry_set_text(GTK_ENTRY(mse_flag),"0");
	gtk_entry_set_text(GTK_ENTRY(ei_flag),"0");
	gtk_entry_set_text(GTK_ENTRY(rst_55),"0");
	gtk_entry_set_text(GTK_ENTRY(rst_65),"0");
	gtk_entry_set_text(GTK_ENTRY(rst_75),"0");
	gtk_entry_set_text(GTK_ENTRY(mask_55),"0");
	gtk_entry_set_text(GTK_ENTRY(mask_65),"0");
	gtk_entry_set_text(GTK_ENTRY(mask_75),"0");
	gtk_entry_set_text(GTK_ENTRY(sid),"0");
	gtk_entry_set_text(GTK_ENTRY(sod),"0");
	gtk_entry_set_text(GTK_ENTRY(sde),"0");
	
	first_time=1; /*start steping from start*/
	
	gsim_set_registers();
	return;
}

/*###################### Show / hide Ioview ######################*/
void show_hide_regflag(void)
{
	if(state_regflag)
	{
		state_regflag=0;
		gtk_widget_hide_all(gsim_regflag_table);
		gsim_update_statusbar(DESC_SBAR,_("Register / Flags table off"));
	}
	else
	{
		state_regflag=1;
		gtk_widget_show_all(gsim_regflag_table);
		gsim_update_statusbar(DESC_SBAR,_("Register / Flags table on"));
	}
	return;
}

/*############### When sid is edited ###################*/
static void on_sid_changed(GtkEditable *was_changed, gpointer data)
{
	gchar *bit;
	bit=gtk_editable_get_chars(was_changed,0,-1);
	if(g_ascii_strcasecmp(bit,"0")&&g_ascii_strcasecmp(bit,"1"))
		gtk_editable_delete_text(was_changed,0,-1);
}

/*############### Make the registers and flag entries ################*/
GtkWidget *gsim_get_regflag_table( void )
{
	/*table for packing registers and flags*/
	GtkWidget *regflag_table;
	regflag_table = gtk_table_new( 6 , 28 , FALSE );
	
	/*pack close button*/
	GtkWidget *regflag_close;
	regflag_close=gsim_small_close_button_new(-1,-1);;
//	gtk_button_set_relief(GTK_BUTTON(regflag_close), GTK_RELIEF_HALF);
//	gtk_widget_set_size_request( regflag_close , 20, 20 );
	gtk_table_attach( GTK_TABLE( regflag_table ), regflag_close, 0 , 1 , 0 , 1 , 0 , 0, 0 , 0 );
	gtk_tooltips_set_tip( gsim_tooltips, regflag_close, _("Close Register Table"),NULL);
	g_signal_connect(regflag_close,"clicked",G_CALLBACK(show_hide_regflag),NULL);
	
	/*pack reset button*/
	GtkWidget *regflag_reset;//,*reset_label;
	regflag_reset=gsim_small_reset_button_new(-1,-1);
/*	reset_label=gtk_label_new("<span size=\"small\">R</span>");
	gtk_label_set_use_markup(GTK_LABEL(reset_label),TRUE);
	gtk_container_add(GTK_CONTAINER(regflag_reset),reset_label);
	gtk_button_set_relief(GTK_BUTTON(regflag_reset), GTK_RELIEF_HALF);
	gtk_widget_set_size_request( regflag_reset , 20,20 );*/
	gtk_table_attach( GTK_TABLE( regflag_table ), regflag_reset, 0 , 1 , 4 , 5 , 0 , 0, 0 , 0 );
	gtk_tooltips_set_tip( gsim_tooltips, regflag_reset, _("Reset Register Table"),NULL);
	g_signal_connect(regflag_reset,"clicked",G_CALLBACK(reset_regflag),NULL);
	
	/*pack future use button*/
	GtkWidget *regflag_f1;
	regflag_f1=gsim_empty_button_new(-1,-1);
//	gtk_button_set_relief(GTK_BUTTON(regflag_f1), GTK_RELIEF_HALF);
//	gtk_widget_set_size_request( regflag_f1 , 22,22 );
	gtk_table_attach( GTK_TABLE( regflag_table ), regflag_f1, 0 , 1 , 1 , 2 , 0 , 0, 0 , 0 );
	
	GtkWidget *regflag_f2;
	regflag_f2=gsim_empty_button_new(-1,-1);
//	gtk_button_set_relief(GTK_BUTTON(regflag_f2), GTK_RELIEF_HALF);
//	gtk_widget_set_size_request( regflag_f2 , 22,22 );
	gtk_table_attach( GTK_TABLE( regflag_table ), regflag_f2, 0 , 1 , 2 , 3 , 0 , 0, 0 , 0 );
	
	GtkWidget *regflag_f3;
	regflag_f3=gsim_empty_button_new(-1,-1);
//	gtk_button_set_relief(GTK_BUTTON(regflag_f3), GTK_RELIEF_HALF);
//	gtk_widget_set_size_request( regflag_f3 , 22,22 );
	gtk_table_attach( GTK_TABLE( regflag_table ), regflag_f3, 0 , 1 , 3 , 4 , 0 , 0, 0 , 0 );
	
	/*put flag in the table*/
	GtkWidget *sign_flag_label;
	sign_flag_label=gtk_label_new("S");
	sign_flag=gtk_entry_new_with_max_length(1);
	gtk_editable_set_editable(GTK_EDITABLE(sign_flag),FALSE);
	gtk_widget_set_size_request( sign_flag,15,-1);
	gtk_entry_set_text(GTK_ENTRY(sign_flag),gsim_values.flags[0]);
	gtk_table_attach( GTK_TABLE( regflag_table ), sign_flag_label, 2 , 3 , 0 , 1 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), sign_flag, 2 , 3 , 1 , 2 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,sign_flag,_("Sign flag"),NULL);
	
	GtkWidget *parity_flag_label;
	parity_flag_label=gtk_label_new("P");
	parity_flag=gtk_entry_new_with_max_length(1);
	gtk_editable_set_editable(GTK_EDITABLE(parity_flag),FALSE);
	gtk_widget_set_size_request( parity_flag,15,-1);
	gtk_entry_set_text(GTK_ENTRY(parity_flag),gsim_values.flags[1]);
	gtk_table_attach( GTK_TABLE( regflag_table ), parity_flag_label, 3 , 4 , 0 , 1 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), parity_flag, 3 , 4 , 1 , 2 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,parity_flag,_("Parity flag"),NULL);
	
	GtkWidget *aux_flag_label;
	aux_flag_label=gtk_label_new("A");
	aux_flag=gtk_entry_new_with_max_length(1);
	gtk_editable_set_editable(GTK_EDITABLE(aux_flag),FALSE);
	gtk_widget_set_size_request( aux_flag,15,-1);
	gtk_entry_set_text(GTK_ENTRY(aux_flag),gsim_values.flags[2]);
	gtk_table_attach( GTK_TABLE( regflag_table ), aux_flag_label, 4 , 5 , 0 , 1 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), aux_flag, 4 , 5 , 1 , 2 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,aux_flag,_("Auxillary flag"),NULL);
	
	GtkWidget *zero_flag_label;
	zero_flag_label=gtk_label_new("Z");
	zero_flag=gtk_entry_new_with_max_length(1);
	gtk_editable_set_editable(GTK_EDITABLE(zero_flag),FALSE);
	gtk_widget_set_size_request( zero_flag,15,-1);
	gtk_entry_set_text(GTK_ENTRY(zero_flag),gsim_values.flags[3]);
	gtk_table_attach( GTK_TABLE( regflag_table ), zero_flag_label, 5 , 6 , 0 , 1 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), zero_flag, 5 , 6 , 1 , 2 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,zero_flag,_("Zero  flag"),NULL);
	
	GtkWidget *carry_flag_label;
	carry_flag_label=gtk_label_new("C");
	carry_flag=gtk_entry_new_with_max_length(1);
	gtk_editable_set_editable(GTK_EDITABLE(carry_flag),FALSE);
	gtk_widget_set_size_request( carry_flag,15,-1);
	gtk_entry_set_text(GTK_ENTRY(carry_flag),gsim_values.flags[4]);
	gtk_table_attach( GTK_TABLE( regflag_table ), carry_flag_label, 6 , 7 , 0 , 1 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), carry_flag, 6 , 7 , 1 , 2 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,carry_flag,_("Carry flag"),NULL);
	
	/*useless padding ( only for style)*/
	GtkWidget *pad1;
	pad1=gtk_label_new("   ");
	gtk_table_attach( GTK_TABLE( regflag_table ), pad1 , 7 , 8 , 0 , 1 ,0,0 , 0,0 );
	
	GtkWidget *pad2;
	pad2=gtk_label_new("          ");
	gtk_table_attach( GTK_TABLE( regflag_table ), pad2 , 18 , 20 , 2 , 3 ,GTK_FILL|GTK_EXPAND,0 , 0,0 );
	
	GtkWidget *pad3;
	pad3=gtk_label_new("    ");
	gtk_table_attach( GTK_TABLE( regflag_table ), pad3, 1 , 2 , 0 , 1 ,0,0 , 0,0 );
	
	GtkWidget *pad4;
	pad4=gtk_label_new("    ");
	gtk_table_attach( GTK_TABLE( regflag_table ), pad4 , 24 , 25 , 2 , 3 ,GTK_FILL|GTK_EXPAND,0 , 0,0);
	
	GtkWidget *pad5;
	pad5=gtk_label_new("    ");
	gtk_table_attach( GTK_TABLE( regflag_table ), pad5, 27 , 28 , 0 , 1 ,0,0 , 0,0 );
	
	/*pack registers*/
	GtkWidget *a_register_label;
	a_register_label=gtk_label_new("A");
	a_register=gtk_entry_new_with_max_length(2);
	gtk_editable_set_editable(GTK_EDITABLE(a_register),FALSE);
	gtk_widget_set_size_request( a_register,30,-1);
	gtk_entry_set_text(GTK_ENTRY(a_register),gsim_values.reg_2[0]);
	gtk_table_attach( GTK_TABLE( regflag_table ), a_register_label, 2 , 4 , 3 , 4 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), a_register, 2 , 4 , 4 , 5 ,0,0 , 0,0 );
	
	GtkWidget *flags_register_label;
	flags_register_label=gtk_label_new("F");
	flags_register=gtk_entry_new_with_max_length(2);
	gtk_editable_set_editable(GTK_EDITABLE(flags_register),FALSE);
	gtk_widget_set_size_request( flags_register,30,-1);
	gtk_entry_set_text(GTK_ENTRY(flags_register),gsim_values.reg_2[1]);
	gtk_table_attach( GTK_TABLE( regflag_table ), flags_register_label, 4 , 6 , 3 , 4 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), flags_register, 4 , 6 , 4 , 5 ,0,0 , 0,0 );
	
	GtkWidget *b_register_label;
	b_register_label=gtk_label_new("B");
	b_register=gtk_entry_new_with_max_length(2);
	gtk_editable_set_editable(GTK_EDITABLE(b_register),FALSE);
	gtk_widget_set_size_request( b_register,30,-1);
	gtk_entry_set_text(GTK_ENTRY(b_register),gsim_values.reg_2[2]);
	gtk_table_attach( GTK_TABLE( regflag_table ), b_register_label, 6 , 8 , 3 , 4 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), b_register, 6 , 8 , 4 , 5 ,0,0 , 0,0 );
	
	GtkWidget *c_register_label;
	c_register_label=gtk_label_new("C");
	c_register=gtk_entry_new_with_max_length(2);
	gtk_editable_set_editable(GTK_EDITABLE(c_register),FALSE);
	gtk_widget_set_size_request( c_register,30,-1);
	gtk_entry_set_text(GTK_ENTRY(c_register),gsim_values.reg_2[3]);
	gtk_table_attach( GTK_TABLE( regflag_table ), c_register_label, 8 , 10 , 3 , 4 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), c_register, 8 , 10 , 4 , 5 ,0,0 , 0,0 );
	
	GtkWidget *d_register_label;
	d_register_label=gtk_label_new("D");
	d_register=gtk_entry_new_with_max_length(2);
	gtk_editable_set_editable(GTK_EDITABLE(d_register),FALSE);
	gtk_widget_set_size_request( d_register,30,-1);
	gtk_entry_set_text(GTK_ENTRY(d_register),gsim_values.reg_2[4]);
	gtk_table_attach( GTK_TABLE( regflag_table ), d_register_label, 10 , 12 , 3 , 4 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), d_register, 10 , 12 , 4 , 5 ,0,0 , 0,0 );
	
	GtkWidget *e_register_label;
	e_register_label=gtk_label_new("E");
	e_register=gtk_entry_new_with_max_length(2);
	gtk_editable_set_editable(GTK_EDITABLE(e_register),FALSE);
	gtk_widget_set_size_request( e_register,30,-1);
	gtk_entry_set_text(GTK_ENTRY(e_register),gsim_values.reg_2[5]);
	gtk_table_attach( GTK_TABLE( regflag_table ), e_register_label, 12 , 14 , 3 , 4 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), e_register, 12 , 14 , 4 , 5 ,0,0 , 0,0 );
	
	GtkWidget *h_register_label;
	h_register_label=gtk_label_new("H");
	h_register=gtk_entry_new_with_max_length(2);
	gtk_editable_set_editable(GTK_EDITABLE(h_register),FALSE);
	gtk_widget_set_size_request( h_register,30,-1);
	gtk_entry_set_text(GTK_ENTRY(h_register),gsim_values.reg_2[6]);
	gtk_table_attach( GTK_TABLE( regflag_table ), h_register_label, 14 , 16 , 3 , 4 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), h_register, 14 , 16 , 4 , 5 ,0,0 , 0,0 );
	
	GtkWidget *l_register_label;
	l_register_label=gtk_label_new("L");
	l_register=gtk_entry_new_with_max_length(2);
	gtk_editable_set_editable(GTK_EDITABLE(l_register),FALSE);
	gtk_widget_set_size_request( l_register,30,-1);
	gtk_entry_set_text(GTK_ENTRY(l_register),gsim_values.reg_2[7]);
	gtk_table_attach( GTK_TABLE( regflag_table ), l_register_label, 16 , 18 , 3 , 4 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), l_register, 16 , 18 , 4 , 5 ,0,0 , 0,0 );
	
	GtkWidget *stack_pointer_label;
	stack_pointer_label=gtk_label_new("SP");
	stack_pointer=gtk_entry_new_with_max_length(4);
	gtk_editable_set_editable(GTK_EDITABLE(stack_pointer),FALSE);
	gtk_widget_set_size_request( stack_pointer,60,-1);
	gtk_entry_set_text(GTK_ENTRY(stack_pointer),gsim_values.reg_4[0]);
	gtk_table_attach( GTK_TABLE( regflag_table ), stack_pointer_label, 10 , 14 , 0 , 1 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), stack_pointer, 10 , 14 , 1 , 2 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,stack_pointer,_("Stack Pointer"),NULL);
	
	GtkWidget *program_counter_label;
	program_counter_label=gtk_label_new("PC");
	program_counter=gtk_entry_new_with_max_length(4);
	gtk_editable_set_editable(GTK_EDITABLE(program_counter),FALSE);
	gtk_widget_set_size_request( program_counter,60,-1);
	gtk_entry_set_text(GTK_ENTRY(program_counter),gsim_values.reg_4[1]);
	gtk_table_attach( GTK_TABLE( regflag_table ), program_counter_label, 14 , 18 , 0 , 1 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), program_counter, 14 , 18 , 1 , 2 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,program_counter,_("Program Counter"),NULL);
	
	/*pack interrupt masks and flags*/
	GtkWidget *rst_label;
	rst_label=gtk_label_new("    RST:");
	gtk_table_attach( GTK_TABLE( regflag_table ), rst_label, 20 , 21 , 1 , 2 ,0,0 , 0,0 );
	
	GtkWidget *mask_label;
	mask_label=gtk_label_new(" MASK:");
	gtk_table_attach( GTK_TABLE( regflag_table ), mask_label, 20 , 21 , 2 , 3 ,0,0 , 0,0 );
	
	GtkWidget *label_55,*label_65,*label_75;
	label_55=gtk_label_new("5.5 ");
	label_65=gtk_label_new("6.5 ");
	label_75=gtk_label_new("7.5 ");
	gtk_table_attach( GTK_TABLE( regflag_table ), label_55, 21 , 22 , 0 , 1 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), label_65, 22 , 23 , 0 , 1 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), label_75, 23 , 24 , 0 , 1 ,0,0 , 0,0 );
	
	rst_55=gtk_entry_new_with_max_length(1);
	gtk_widget_set_size_request( rst_55,20,-1);
	gtk_editable_set_editable(GTK_EDITABLE(rst_55),FALSE);
	gtk_entry_set_text(GTK_ENTRY(rst_55),gsim_values.flags[5]);
	gtk_table_attach( GTK_TABLE( regflag_table ), rst_55, 21 , 22 , 1 , 2 ,0,0 , 0,0 );
	
	rst_65=gtk_entry_new_with_max_length(1);
	gtk_widget_set_size_request( rst_65,20,-1);
	gtk_editable_set_editable(GTK_EDITABLE(rst_65),FALSE);
	gtk_entry_set_text(GTK_ENTRY(rst_65),gsim_values.flags[6]);
	gtk_table_attach( GTK_TABLE( regflag_table ), rst_65, 22 , 23 , 1 , 2 ,0,0 , 0,0 );
	
	rst_75=gtk_entry_new_with_max_length(1);
	gtk_widget_set_size_request( rst_75,20,-1);
	gtk_editable_set_editable(GTK_EDITABLE(rst_75),FALSE);
	gtk_entry_set_text(GTK_ENTRY(rst_75),gsim_values.flags[7]);
	gtk_table_attach( GTK_TABLE( regflag_table ), rst_75, 23 , 24 , 1 , 2 ,0,0 , 0,0 );
	
	mask_55=gtk_entry_new_with_max_length(1);
	gtk_widget_set_size_request( mask_55,20,-1);
	gtk_editable_set_editable(GTK_EDITABLE(mask_55),FALSE);
	gtk_entry_set_text(GTK_ENTRY(mask_55),gsim_values.flags[8]);
	gtk_table_attach( GTK_TABLE( regflag_table ), mask_55, 21 , 22 , 2 , 3 ,0,0 , 0,0 );
	
	mask_65=gtk_entry_new_with_max_length(1);
	gtk_widget_set_size_request( mask_65,20,-1);
	gtk_editable_set_editable(GTK_EDITABLE(mask_65),FALSE);
	gtk_entry_set_text(GTK_ENTRY(mask_65),gsim_values.flags[9]);
	gtk_table_attach( GTK_TABLE( regflag_table ), mask_65, 22 , 23 , 2 , 3 ,0,0 , 0,0 );
	
	mask_75=gtk_entry_new_with_max_length(1);
	gtk_widget_set_size_request( mask_75,20,-1);
	gtk_editable_set_editable(GTK_EDITABLE(mask_75),FALSE);
	gtk_entry_set_text(GTK_ENTRY(mask_75),gsim_values.flags[10]);
	gtk_table_attach( GTK_TABLE( regflag_table ), mask_75, 23 , 24 , 2 , 3 ,0,0 , 0,0 );
	
	GtkWidget *mse_flag_label;
	mse_flag_label=gtk_label_new(" MSE:");
	mse_flag=gtk_entry_new_with_max_length(1);
	gtk_editable_set_editable(GTK_EDITABLE(mse_flag),FALSE);
	gtk_widget_set_size_request( mse_flag,20,-1);
	gtk_entry_set_text(GTK_ENTRY(mse_flag),gsim_values.flags[11]);
	gtk_table_attach( GTK_TABLE( regflag_table ), mse_flag_label, 20 , 21 , 4 , 5 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), mse_flag, 21 , 22 , 4 , 5 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,mse_flag,_("Mask set enable flag"),NULL);
	
	GtkWidget *ei_flag_label;
	ei_flag_label=gtk_label_new(" EI:");
	ei_flag=gtk_entry_new_with_max_length(1);
	gtk_editable_set_editable(GTK_EDITABLE(ei_flag),FALSE);
	gtk_widget_set_size_request( ei_flag,20,-1);
	gtk_entry_set_text(GTK_ENTRY(ei_flag),gsim_values.flags[12]);
	gtk_table_attach( GTK_TABLE( regflag_table ), ei_flag_label, 22 , 23 , 4 , 5 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), ei_flag, 23 , 24 , 4 , 5 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,ei_flag,_("Enable Interrupt flag"),NULL);
	
	GtkWidget *sid_label;
	sid_label=gtk_label_new("  SID:");
	sid=gtk_entry_new_with_max_length(1);
	gtk_editable_set_editable(GTK_EDITABLE(sid),TRUE);
	gtk_widget_set_size_request( sid,20,-1);
	gtk_entry_set_text(GTK_ENTRY(sid),"0");
	gtk_table_attach( GTK_TABLE( regflag_table ), sid_label, 25 , 26 , 1 , 2 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), sid, 26 , 27 , 1 , 2 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,sid,_("Serial input"),NULL);
	g_signal_connect(sid,"changed",G_CALLBACK(on_sid_changed),NULL);
	
	GtkWidget *sod_label;
	sod_label=gtk_label_new("SOD:");
	sod=gtk_entry_new_with_max_length(1);
	gtk_editable_set_editable(GTK_EDITABLE(sod),FALSE);
	gtk_widget_set_size_request( sod,20,-1);
	gtk_entry_set_text(GTK_ENTRY(sod),"0");
	gtk_table_attach( GTK_TABLE( regflag_table ), sod_label, 25 , 26 , 2 , 3 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), sod, 26 , 27 , 2 , 3 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,sod,_("Serial output"),NULL);
	
	GtkWidget *sde_label;
	sde_label=gtk_label_new("SDE:");
	sde=gtk_entry_new_with_max_length(1);
	gtk_editable_set_editable(GTK_EDITABLE(sde),FALSE);
	gtk_widget_set_size_request( sde,20,-1);
	gtk_entry_set_text(GTK_ENTRY(sde),"0");
	gtk_table_attach( GTK_TABLE( regflag_table ), sde_label, 25 , 26 , 4 , 5 ,0,0 , 0,0 );
	gtk_table_attach( GTK_TABLE( regflag_table ), sde, 26 , 27 , 4 , 5 ,0,0 , 0,0 );
	gtk_tooltips_set_tip( gsim_tooltips,sde,_("Enable serial I/O"),NULL);
	
	
	/*set all entries values*/
	reset_regflag();
	
	/*pack table in frame and return*/
	GtkWidget *regflag_frame;
	regflag_frame= gtk_frame_new( NULL );
	gtk_container_add( GTK_CONTAINER( regflag_frame ), regflag_table );
	
	return regflag_frame;
}
